#ifndef __echo_kenny_dkfjiwoo3w3__
#define __echo_kenny_dkfjiwoo3w3__

#include "brick/brick.hpp"

namespace ha
{
    namespace brick
    {
        /*********************************************************************
         * @brief 虚拟控制台， 这里一般做为虚拟串口
         */
        class echo_t : public brick_t
        {
        public:
            echo_t( aio_t aio, const json_t& args )
            {
            }

            ~echo_t()
            {
            }

            int send( const void* p, size_t n ) override;

            void close() override {}

            bool settings( const json_t& args ) override;

        };

        /*********************************************************************
         * @brief 设置参数
         */
        inline bool echo_t::settings( const json_t& args )
        {
            return true;
        }

        /*********************************************************************
         * @brief 设置参数
         */
        inline int echo_t::send( const void* p, size_t n )
        {
            auto b = (uint8_t*)p;

            auto pb = new hude::buffer_t{ b, b + n };

            hude::aio::context_t<>::aio()->task_commit( [=]{
                if( cb_recv_ ) this->cb_recv_( *pb );
                delete pb;
            } );

            return true;
        }

    } //namespace brick
} //namespace ha

#endif //__echo_kenny_dkfjiwoo3w3__

